package com.insurance.controller;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.pojo.*;
import com.insurance.service.AuthorityService;
import com.insurance.utils.ConversionDateUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/27 14:23
 * Description:设置
 * Version: V1.0
 */
@Api(value = "设置模块内容",tags = "设置模块内容API")
@Controller
public class AuthorityController {

    @Autowired
    private ResultData resultData;

    @Autowired
    private AuthorityService authorityService;
    @RequestMapping(value = "/queryadmin.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询管理员信息--1.可用，0.不可用",notes = "查询管理员信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData queryAuthorityList() throws Exception{
       resultData=authorityService.queryAuthorityList();
        return resultData;
    }



    @RequestMapping(value = "/deleteAuthority.do",method = RequestMethod.GET)
    @ApiOperation(value = "删除管理员账户信息",notes = "删除管理员账户信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParam(name = "userId",value = "用户id",dataType = "int")
    @ResponseBody
    public ResultData deleteAuthority(@RequestParam int userId) throws Exception{
        ResultData  resultData =authorityService.deleteAuthority(userId);
        return resultData;
    }

    @RequestMapping(value = "/updateAuthority.do",method = RequestMethod.POST)
    @ApiOperation(value = "修改用户账号信息",notes = "修改用户账号信息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData editAuthority(@RequestBody UserPermissions userPermission) throws Exception{
        ResultData resultData=authorityService.editAuthority(userPermission);
        return resultData;
    }


    @RequestMapping(value = "/addAuthority.do",method = RequestMethod.POST)
    @ApiOperation(value = "添加用户及权限",notes = "添加用户及权限接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData addAuthority(@RequestBody UserPermissions userPermission)throws SQLException{

        ResultData resultData=authorityService.addAuthority(userPermission);
        return resultData;
    }

    @RequestMapping(value = "/editAuthorityStatu.do",method = RequestMethod.GET)
    @ApiOperation(value = "修改管理员账户是否可用",notes = "修改管理员账户是否可用接口",httpMethod = "Get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParams({
    @ApiImplicitParam(name = "userId",value = "用户id",dataType = "int",required = true,paramType = "query"),
    @ApiImplicitParam(name = "userStatu",value = "用户账户是否可用-1.可用，0.不可用",dataType = "int",required = true,paramType = "query")
    })
    @ResponseBody
    public ResultData editAuthorityStatu(Integer userId,Integer userStatu) throws Exception{
        ResultData resultData= authorityService.editAuthorityStatu(userId,userStatu);
        return resultData;
    }

    @RequestMapping(value = "/addCity.do",method = RequestMethod.GET)
    @ApiOperation(value = "添加城市",notes = "添加城市接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParam(name = "cityId",value = "市级id",required = true)
    @ResponseBody
    public ResultData addCity(int cityId) throws Exception{
        ResultData resultData=authorityService.addCity(cityId);
        return resultData;
    }

    @RequestMapping(value = "/deleteCity.do",method = RequestMethod.GET)
    @ApiOperation(value = "删除城市",notes = "删除城市接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParam(name = "cityId",value = "市级id",required = true)
    @ResponseBody
    public ResultData deleteCity(int cityId) throws Exception{
        ResultData resultData=authorityService.deleteCity(cityId);
        return resultData;
    }
    @RequestMapping(value = "/queryByProvince.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询省",notes = "查询省接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData queryByProvince() throws Exception{
        ResultData resultData=authorityService.queryPerAll();
        return resultData;
    }
    @RequestMapping(value = "/queryByCityStrtu.do",method = RequestMethod.GET)
    @ApiOperation(value = "根据省id查询未开通市",notes = "根据省id查询未开通市接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParam(name = "province_id",value = "省级id",required = true)
    @ResponseBody
    public ResultData queryByCityStrtu(int province_id) throws Exception{
        ResultData resultData=authorityService.queryByCityStrtu(province_id);
        return resultData;
    }

    @RequestMapping(value = "/queryCityAll.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询已开通城市",notes = "查询开通城市接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData queryCityAll() throws Exception{
        ResultData resultData = authorityService.queryCityAll();
        return resultData;
    }
    @RequestMapping(value = "/queryCityAllCount.do",method = RequestMethod.GET)
    @ApiOperation(value = "统计已开通城市",notes = "统计开通城市接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData queryCityAllCount() throws Exception{
        ResultData resultData = authorityService.queryCityAllCount();
        return resultData;
    }


    @RequestMapping(value = "/addInform.do",method = RequestMethod.POST)
    @ApiOperation(value = "推送消息",notes = "推送消息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData addInform(@RequestBody Information information) throws SQLException {
        System.out.println(information);
         resultData=authorityService.addInform(information);
        return resultData;
    }

    @RequestMapping(value = "/queryInform.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有消息",notes = "查询所有接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData queryInform() throws Exception{
        ResultData resultData=authorityService.queryInform();
        return resultData;
    }
    @RequestMapping(value = "/delInform.do",method = RequestMethod.POST)
    @ApiOperation(value = "删除消息",notes = "删除消息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData delInform(@RequestBody Information information) throws Exception{
        ResultData resultData=authorityService.delInform(information);
        return resultData;
    }

}
